package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@Api(tags = "店铺管理")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    RedisTemplate redisTemplate;

    /**
     * 设置店铺状态接口
     * 该接口用于更新店铺的状态信息，例如开启或关闭店铺。
     *
     * @param status 店铺状态码
     * @return 返回操作结果，成功则返回成功信息
     */
    @Operation(summary = "设置店铺状态")
    @PutMapping("/{status}")
    public Result addShopStatus(@PathVariable Integer status) {
        log.info("设置店铺状态:{}", status == 1 ? "营业中" : "打样中");
        redisTemplate.opsForValue().set("SHOP_STATUS", status);
        return Result.success();
    }


    /**
     * 查询店铺状态接口
     * 该接口用于获取店铺的当前状态
     *
     * @return Result<Integer> 返回店铺状态码
     */
    @Operation(summary = "查询店铺状态")
    @GetMapping("/status")
    public Result<Integer> getStatus() {
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("查询店铺状态:{}", shopStatus == 1 ? "营业中" : "打样中");
        return Result.success(shopStatus);
    }
}
